﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using IBatisNet.DataMapper;

namespace WS
{
    using WS.Domain;
    /// <summary>
    /// Summary description for Service1
    /// </summary>
    [WebService(Namespace = "WS")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class Service1 : System.Web.Services.WebService 
    {
        ISqlMapper sqlMapper;
        List<Sinhvien> list;

        public Service1()
        {
            sqlMapper = Mapper.Instance();
        }

        #region Web Method Sinh viên Base

            [WebMethod]
            public List<Sinhvien> ReadList()
            {
                list = (List<Sinhvien>)sqlMapper.QueryForList<Sinhvien>("getSV",null);
                return list;
            }

            [WebMethod]
            public bool InsertSV(Sinhvien sv)
            {
                try
                {
                    sqlMapper.Insert("insertSV",sv);
                    return true;
                }
                catch (Exception) { return false; }
            }

            [WebMethod]
            public bool UpdateSV(Sinhvien sv)
            {
                try
                {
                    sqlMapper.Update("updateSV", sv);
                    return true;
                }
                catch (Exception) { return false; }
            }

            [WebMethod]
            public bool DeleteSV(int id) 
            {
                try
                {
                    sqlMapper.Delete("deleteSV", id);
                    return true;
                }
                catch (Exception) { return false; }
            }

        #endregion

        #region Web Method Sinh viên Support

            [WebMethod]
            public List<Sinhvien> Select_SV_Lop(int lophoc_id)
            {
                try
                {
                    list = (List<Sinhvien>)sqlMapper.QueryForList<Sinhvien>("getSV_Lop", lophoc_id);
                    return list;
                }
                catch (Exception) { return null; }
               
            }

            [WebMethod]
            public List<Sinhvien> Check_MSSV(Sinhvien sv)
            {
                try
                {
                    list = (List<Sinhvien>)sqlMapper.QueryForList<Sinhvien>("check_MSSV", sv);
                    return list;
                }
                catch (Exception) { return null; }

            }

        #endregion
    }
}